<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目名称">
          <el-input v-model="queryParam.qry_projectName"></el-input>
        </el-form-item>
        <el-form-item label="项目编号">
          <el-input v-model="queryParam.qry_projectCode" style="width:130px"></el-input>
        </el-form-item>
        <el-form-item label="项目经理">
          <el-input v-model="queryParam.qry_projectManager" placeholder="姓名/工号" style="width:130px"></el-input>
        </el-form-item>
        <el-form-item label="单据编号">
          <el-input v-model="queryParam.qry_docno" placeholder=""></el-input>
        </el-form-item>
        <!-- <el-form-item label="单据日期" prop="qry_begindocdate">
          <el-date-picker v-model="queryParam.qry_begindocdate" type="date" style="width:150px" value-format="yyyy-MM-dd" placeholder="开始时间" />至
          <el-date-picker v-model="queryParam.qry_enddocdate" type="date" style="width:150px" value-format="yyyy-MM-dd" placeholder="结束时间" />
        </el-form-item> -->
        <el-form-item label="单据状态">
          <el-select v-model="queryParam.qry_state" clearable>
            <el-option v-for="item in codeModel.stateList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" :isDisplayExport="false" :isDisplayDeleteBatch="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column>
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="dispprojectid" label="项目" width="150px" sortable="custom" sort-by="dispprojectid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column v-if="editFlag" prop="code" label="项目编号" width="130px" sortable="custom" sort-by="code" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column v-if="editFlag" prop="projectmanagername" label="项目经理" width="110px" sortable="custom" sort-by="projectmanagername" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column v-if="editFlag" prop="projectmanagercode" label="项目经理工号" width="110px" sortable="custom" sort-by="projectmanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcontractid" label="合同" width="150px" sortable="custom" sort-by="dispcontractid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="contractname" label="合同名称" width="150px" sortable="custom" sort-by="contractname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="changereason" label="变更原因" width="150px" sortable="custom" sort-by="changereason" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="contractorgname" label="合同所属组织" width="150px" sortable="custom" sort-by="contractorgname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="contractorgname2" label="合同所属组织(新)" width="150px" sortable="custom" sort-by="contractorgname2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="contractorgcode" label="合同所属组织编码" width="150px" sortable="custom" sort-by="contractorgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="contractorgcode2" label="合同所属组织编码(新)" width="150px" sortable="custom" sort-by="contractorgcode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="contractdeptname" label="合同所属部门" width="150px" sortable="custom" sort-by="contractdeptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="contractdeptname2" label="合同所属部门(新)" width="150px" sortable="custom" sort-by="contractdeptname2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="contractdeptcode" label="合同所属部门编码" width="150px" sortable="custom" sort-by="contractdeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="contractdeptcode2" label="合同所属部门编码(新)" width="150px" sortable="custom" sort-by="contractdeptcode2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column prop="customerid" label="客户id" width="150px" sortable="custom" sort-by="customerid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="customername" label="客户名称" width="150px" sortable="custom" sort-by="customername" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="contractcode" label="合同编号" width="150px" sortable="custom" sort-by="contractcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="contractdate" label="合同日期" width="170px" sortable="custom" sort-by="contractdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="contractmoney" label="合同金额(原)" width="150px" sortable="custom" sort-by="contractmoney" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="contractmoney2" label="合同金额(新)" width="150px" sortable="custom" sort-by="contractmoney2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="billmoney" label="已开票金额" width="150px" sortable="custom" sort-by="billmoney" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="receiver" label="收件人(原)" width="150px" sortable="custom" sort-by="receiver" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiver2" label="收件人(新)" width="150px" sortable="custom" sort-by="receiver2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="phone" label="收件人电话(原)" width="150px" sortable="custom" sort-by="phone" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="phone2" label="收件人电话(新)" width="150px" sortable="custom" sort-by="phone2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="postal" label="回寄地址(原)" width="150px" sortable="custom" sort-by="postal" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="postal2" label="回寄地址(新)" width="150px" sortable="custom" sort-by="postal2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="courier" label="快递方式(原)" width="150px" sortable="custom" sort-by="courier" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="courier2" label="快递方式(新)" width="150px" sortable="custom" sort-by="courier2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="couriernumber" label="快递单号(原)" width="150px" sortable="custom" sort-by="couriernumber" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="couriernumber2" label="快递单号(新)" width="150px" sortable="custom" sort-by="couriernumber2" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="orgname" label="申请公司" width="150px" sortable="custom" sort-by="orgname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="orgcode" label="申请公司编码" width="150px" sortable="custom" sort-by="orgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="deptname" label="申请部门" width="150px" sortable="custom" sort-by="deptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deptcode" label="申请部门编码" width="150px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="username" label="申请人姓名" width="150px" sortable="custom" sort-by="username" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="usercode" label="申请人工号" width="150px" sortable="custom" sort-by="usercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="docdate" label="单据日期" width="170px" sortable="custom" sort-by="docdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="submitdate" label="提交日期" width="170px" sortable="custom" sort-by="submitdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="docno" label="单据编号" width="150px" sortable="custom" sort-by="docno" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="flowid" label="审批流程" width="150px" sortable="custom" sort-by="flowid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="latestphase" label="最新阶段" width="150px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="state" label="状态" width="150px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
					<template slot-scope="scope">
						<el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
						<el-tag v-else type="danger">否</el-tag>
					</template>
				</el-table-column> -->

        <!-- <el-table-column label="操作" width="220px" v-slot="scope" fixed="right">
          <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', scope.row.id)">编辑</el-button>
          <el-button type="text" icon="el-icon-delete" :disabled="scope.row.state !== 0 && scope.row.state !== 2" @click="doDelete(scope.row.id)">删除</el-button>
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column> -->

        <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">操作<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-dropdown-item>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="scope.row.state !== 0 && scope.row.state !== 2">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="(scope.row.state !== 0 && scope.row.state !== 2) || !editFlag" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { checkPermission } from '@tapui/utils/permission'
/** 子组件 */
import tlEdit from './edit'
import { validateNull } from '@tapui/utils/validate'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'pmContractChange',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '项目合同信息变更申请-列表查询',
      urlPrefix: '/pm/contractChange/',
      url: {
        queryCodeList: '/pm/contractChange/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'pmContractChange.createon',
        sord: 'desc'
      },
      editFlag: true
    }
  },
  methods: {
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      // 判断双击打开是查看还是编辑
      if (row.state === 0 || row.state === 2) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    },
    /** 表格列排序 */
    doSortChange(columnInfo, prop, order) {
      if (columnInfo.column === null) {
        return
      }
      // 不排序
      if (validateNull(columnInfo.order)) {
        Object.assign(this.sorterInfo, this.sorterDefaultInfo)
        this.loadData({})
        return
      }
      // 判断是否处理垃圾数据
      if (columnInfo.column.sortBy.indexOf('.') !== -1) {
        columnInfo.column.sortBy = columnInfo.column.sortBy.substring(columnInfo.column.sortBy.lastIndexOf('.') + 1)
      }
      if (columnInfo.prop.indexOf('.') !== -1) {
        columnInfo.prop = columnInfo.prop.substring(columnInfo.prop.lastIndexOf('.') + 1)
      }
      if (columnInfo.column.sortBy === 'code' || columnInfo.column.sortBy === 'projectmanagercode' || columnInfo.column.sortBy === 'projectmanagername') {
        // 升序或者降序排序
        if (columnInfo.column.sortBy) {
          columnInfo.column.sortBy = 'PmProject.' + columnInfo.column.sortBy
          this.sorterInfo.sidx = columnInfo.column.sortBy
        } else {
          columnInfo.prop = 'PmProject.' + columnInfo.prop
          this.sorterInfo.sidx = columnInfo.prop
        }
      } else {
        // 升序或者降序排序
        if (columnInfo.column.sortBy) {
          columnInfo.column.sortBy = 'pmContractChange.' + columnInfo.column.sortBy
          this.sorterInfo.sidx = columnInfo.column.sortBy
        } else {
          columnInfo.prop = 'pmContractChange.' + columnInfo.prop
          this.sorterInfo.sidx = columnInfo.prop
        }
      }
      this.sorterInfo.sord = columnInfo.order.replace('ending', '')
      this.loadData({})
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    }
  }
}
</script>

<style scoped></style>

